import {Base,Item} from '../base';
class bjcg extends Base{
    constructor(){
        super();
        this.name="北京市政府采购";
        this.enabled = true;
        this.encode = "utf-8";
        this.debug = false;
        this.timeout = 1000000;
        this.collection = "ztb";
        this.collectionShowName = "招投标信息";
        this.keyField = "title";
    }
    getItems(pageIndex:number) :Item[]{
        let  result:Item[]=[];
        let num=pageIndex+1;
        let url=`http://www.bgpc.gov.cn/defaults/news/news/page/${num}%2Ftid%2F2`;
        let content=this.spider.getSync(url);
        let $=this.cheerio.load(content);
        let that =this;
        $('.content-right-content-center li').each(function (index, ele) {
            let  item=that.buildItem();
            item.title=$(ele).find('a').text().trim();
            let uri='http://www.bgpc.gov.cn'+$(ele).find('a').attr('href');
            (<any>item).url='http://www.bgpc.gov.cn'+$(ele).find('a').attr('href');
            item.source=that.name;
            result=that.getExtraItem(uri,item,result);
        });

        return result;
    }
    getExtraItem(url :string ,item :Item,result :Item[]) :Item[]{
        let content =this.spider.getSync(url);
        let $ =this.cheerio.load(content);
        (<any>item).content=$('.content-right-content').html();
        result.push(item);
        return result;
      }
      getPageCount ():number{
          return 20;
      }
}
module.exports=new bjcg();